package com._119yn.host.gst200.cansocket.codec;

import com._119yn.host.gst200.cansocket.message.CanFrame;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class CanFrameEncoder extends ChannelOutboundHandlerAdapter {

    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
        if (msg instanceof CanFrame canFrame) {
            log.debug("SEND:{}", canFrame.getLineData());
            ctx.write(canFrame.getLineData());
        } else {
            ctx.write(msg);
        }
    }

}
